<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    title="Cancel"
    width="30%">
    <dynForm
      ref="dataForm"
      :info-form="infoForm"
      :search-tags="searchTags"
      :is-inline="false"
    />
    <span slot="footer">
      <el-button
        icon="el-icon-circle-close"
        @click="handleClose"
      >{{ $t("cancel") }}</el-button>
      <el-button
        v-btnThrottle="doSave"
        type="primary"
        icon="el-icon-receiving"
      >{{ $t("save") }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { canCelTrackIn } from '@/api/production/webOUI'
import { replaceStr } from '@/utils/notification'
export default {
  name: 'ModelCancel',
  data() {
    const searchTags = [
      { label: this.$t('Reason'), prop: 'reason', tag: 'DynTextarea', row: 2, width: '100%' }
    ]
    return {
      dialogVisible: false,
      infoForm: {},
      form: {},
      searchTags: Object.freeze(searchTags)
    }
  },
  methods: {
    async handleOpen(row) {
      this.form = row
      this.dialogVisible = true
    },
    doSave() {
      const { eqpId, lotId, portId } = this.form
      canCelTrackIn(this.$clearNull({ eqpId, lotId, portId, reason: this.infoForm.reason })).then(res => {
        // this.$betterTips(res, this.handleClose, this.handleUpdate)
        if (res.code === 1) {
          this.$alert(replaceStr(this.$t(String(res.message)), res.data), this.$t('cancelTrackInInfo'), {
            confirmButtonText: this.$t('determine'),
            type: 'success'
          })
          this.handleClose()
          this.handleUpdate()
        } else {
          this.$alert(replaceStr(this.$t(String(res.message)), res.data), this.$t('cancelTrackInInfo'), {
            confirmButtonText: this.$t('determine'),
            type: 'error',
            callback: action => {
              this.trackOutLoading = false
            }
          })
        }
      })
    },
    handleClose() {
      Object.assign(this.$data, this.$options.data.call(this))
    },
    handleUpdate() {
      this.$emit('initList')
    }
  }
}
</script>
